<template>
	<view class="batchchangecore">
		<view class="ag-topbg"></view>
		<view class="batchchangecore-card">
			<view class="batchchangecore-card__head">
				<image src="../../static/img/icon-qrcode.png" />
				<text>批量扫描换芯</text>
			</view>
			<AGInput readonly icon="qrcode" placeholder="物流码" @openQrcode="openScanCode" />
			<view class="ag-spacer10"></view>
			<!-- 滤芯列表 -->
			<block v-for="(maintenanceItem , index) in MaintainPartList" :key="maintenanceItem.FilterTypeId">
				<!-- <view class="core-item">
					<image class="core-item__pic" :src="getImage(maintenanceItem.Img)"/>
					<image src="../../static/img/icon-close-black.png" class="core-item__del" @click="onDeleteItem(index)"/>
					<view class="core-item__body">
						<view class="core-item__head">
							<text class="core-item__name">{{maintenanceItem.PartsNum}}</text>
							<view class="ag-status-tag">
								<text>{{maintenanceItem.AppBrief}}</text>
							</view>
						</view>
						<view class="core-item__desc">
							{{maintenanceItem.PartsName}}
						</view>
						<view class="core-item__tags">
							<view class="ag-status-tag">
								<text>零售价：{{maintenanceItem.Price}}</text>
							</view>
							<view class="ag-status-tag">
								<text>网点库存：{{maintenanceItem.SiteStock}}</text>
							</view>
							<!-- <view class="ag-status-tag">
								<text>保养周期：{{maintenanceItem.MaintainPeriod}}</text>
							</view>
						</view>
					</view>
				</view>-->
				<MaintainPartItem :IsShowDeleteBtn="true"
				:maintenanceItem="maintenanceItem"
				:Image="getImage(maintenanceItem.Img)"
				@onDeleteItem="onDeleteItem(index)"></MaintainPartItem>
			</block>
			
			<view class="batchchangecore-card__footer">
				<button class="cu-btn lg primary block" @click="onBatchConfirm">确定</button>
				<button class="cu-btn lg primary block plain" @click="onBatchCancel">取消</button>
			</view>
		</view>
		<view class="ag-spacer30"></view>
	</view>
</template>
<script>
	import AGInput from '@/components/AGInput';
	import MaintainPartItem from '@/components/MaintainPartItem';
	export default {
		components: {
			AGInput,
			MaintainPartItem,
		},
		data() {
			return {
				PartsNum: '',
				woid: '',
				MaintainPartList: [],
				proIndex:'',
			}
		},
		onLoad(e) {
			this.proIndex = e.proIndex;
			this.woid = e.WoId;
		},
		methods: {
			openScanCode(e) {
				// uni.showLoading({
				// 	mask: true,
				// 	title: "加载中.."
				// });
				uni.scanCode({
					scanType: 'barCode',
					success: (res) => {
						//console.log('条码类型：' + res.scanType);
						//console.log('条码内容：' + res.result);
						this.PartsNum = res.result;
						uni.showLoading({
							mask: true,
						});
						this.GetMaintainPartInfoByPartNum().then((succ) => {
							debugger;
							this.MaintainPartList.push(succ[0]);
							//this.maintainInfo.IsDisabledReplacePurchasedByOneself
							uni.hideLoading();
						}, (err) => {
							console.log(err);
							uni.hideLoading();
						});
					},
				});
			},
			async GetMaintainPartInfoByPartNum() {
				let result = await this.workordercompleteservice.GetMaintainPartInfoByPartNum(this.UserInfo.mobile,
					this.PartsNum, this.woid, this.UserInfo.RetId);
				if (result && result.RetBool) {
					if (result.RetObject) {
						return JSON.parse(result.RetObject);
					}
				} else {
					console.log(result.RetMsg);
					throw result.RetMsg
				}
				return null;
			},
			onDeleteItem(Index){
				this.MaintainPartList.splice(Index,1);
			},	
			onBatchConfirm(e){
				let parm = {
					proIndex:this.proIndex,
					MaintainList:this.MaintainPartList,
				}
				uni.$emit("onBatchConfirm",parm);
				uni.navigateBack();
			},
			onBatchCancel(e){
				uni.navigateBack();
			},
			getImage(image) {
				return (image != null && image != 'null' && image != '') ?
					"data:image/jpeg;base64," + image : "";
			},
		},

	}
</script>
<style lang="scss">
	@import "./index.scss";
</style>
